﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using VerbrauchProcessor.DatabaseAccess.DataModel;

namespace VerbrauchProcessor.DatabaseAccess.Reader
{
	/// <summary>
	/// 
	/// </summary>
	public class MDBReader
	{
		
		public IList<Sample> Read(string sDatabaseSource)
		{
			IList<Sample> measurments = new List<Sample>();
			OleDbConnection myConnection = null;
			OleDbDataReader dbReader = null;

			myConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;
												User Id=; 
												Password=; 
												Data Source="+sDatabaseSource);
			myConnection.Open();
			

			OleDbCommand cmd = myConnection.CreateCommand();
			cmd.CommandText = "SELECT * FROM Verbrauch";
			dbReader = cmd.ExecuteReader();

			

			while (dbReader.Read())
			{
				DateTime date = (DateTime)dbReader.GetValue(1);
				decimal wasser = Convert.ToDecimal(dbReader.GetValue(2));
				decimal strom = Convert.ToDecimal(dbReader.GetValue(3));
				decimal gas = Convert.ToDecimal(dbReader.GetValue(4));

				Sample measurement = new Sample(date, strom, gas, wasser);
				measurments.Add(measurement);
			}

			dbReader.Close();
			myConnection.Close();

			return measurments;
		}
	}
}
